'use strict';
/**
 * Created by ylzhang on 2015/10/31.
 */
define([
        'angular',
        'app/core/editor'
    ],
    function(angular) {
        angular.module('ad.editor').controller(
            "adPluginGaugeEditorController",['$rootScope','$scope','Notification',function($rootScope,$scope,Notification) {
                //$scope.indexPlugin 指标控件实例
                //$scope.bindingOfIndex 指标绑定数据，[]类型
                //$scope.eventsOfIndex 指标事件对象，[]类型
                //$scope.optionOfIndex 指标配置参数，{}类型
                //$scope.extendOfIndex 指标属性扩展，{}类型
                //$scope.bindPivotEvent 钻取事件设置
                //ad.index.option.changed 配置编辑器更新事件


                $scope.currentSeries = undefined;
                $scope.currentBinding = undefined;
                $scope.currentSeriesOption = undefined;

                if(!$scope.extendOfIndex)
                    $scope.extendOfIndex = {};

                if(!$scope.extendOfIndex.SeriesOption)
                    $scope.extendOfIndex.SeriesOption = [];

                $scope.addSeries = function () {
                    $scope.currentSeriesOption = {
                        SeriesName:'序列_' + new Date().getSeconds(),
                        DataSetCode:'',
                        DataName:'',
                        DataValue:''
                    };
                    $scope.currentBinding = undefined;
                    $scope.extendOfIndex.SeriesOption.push($scope.currentSeriesOption);
                };

                $scope.removeSeries = function(){
                    if($scope.currentBinding){
                        var index = $scope.extendOfIndex.SeriesOption.indexOf($scope.currentSeriesOption);
                        $scope.extendOfIndex.SeriesOption.splice(index,1)
                        $scope.currentBinding = undefined;
                    }
                };

                $scope.selectedSeries = function () {
                    $scope.currentBinding = _.findWhere($scope.bindingOfIndex,{DataSetCode:$scope.currentSeriesOption.DataSetCode});
                };

                $scope.bindingChanged = function (binding) {
                    if($scope.currentSeriesOption)
                        $scope.currentSeriesOption.DataSetCode = binding.DataSetCode;
                };


                $scope.eventSelect = function () {
                   /* $scope.bindPivotEvent({
                        Event:"SeriesClick",
                        Params:[
                            {Value:"SeriesName",Name:"序列名称"},
                            {Value:"Dimension",Name:"序列维度值"},
                            {Value:"Measure",Name:"序列度量值"}
                        ]
                    });*/
                };
            }]
        );
    });